module PicturesHelper
  def picture_galleries_value
    if action_name == "show"
      @picture.galleries.collect{|ga| ga.name + "<br/>"}
    else
      rvalue = %{<ul id="all_galleries" class="checklist">}
      Gallery.all.each_with_index do |ga,i|
        bg = row_class(i)
        input_id = "gal_#{ga.id}"
        #checked = (@picture.gallery_ids.include?(ga.id) ? "checked" : "")
        checked = ( (@picture.gallery_ids.include?(ga.id) || params["gal_#{ga.id}"]) ?  "checked" : "")
        bg << "_" << checked if checked.length > 0
        rvalue << <<-HTML
          <li class="#{bg}">
            <label id="lbl_#{input_id}" for="#{input_id}" onclick="do_highlight('#{input_id}')">
            <input id="#{input_id}" name="#{input_id}" type="checkbox" #{checked}/>&nbsp;&nbsp;#{ga.name}
            </label>
          </li>
        HTML
      end
      rvalue << "</ul>"
    end
  end

  def picture_name_value
    if action_name == "show"
      h @picture.name 
    else
      text_field :picture, :name
    end
  end

  def picture_description_value
    if action_name == "show"
      h @picture.description 
    else
      text_area :picture, :description
    end
  end

  def picture_image_value
    if action_name == "show"
      image_tag(@picture.image.url)  + "<br/>" + image_tag(@picture.image.url(:thumb))
    else
      file_field :picture, :image
    end
  end


end
